<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>C语言程序设计诊断专家系统</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css">
  <link rel="stylesheet" href="https://static.pingendo.com/bootstrap/bootstrap-4.1.3.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.0/codemirror.css" integrity="sha256-o/v/5fOniPHMAww4EAIfRBFV0SeoqksPrY0Yq5x+wSM=" crossorigin="anonymous" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.0/addon/hint/show-hint.css" integrity="sha256-9PjI1IwVXcv44E37KbDVAJdEYNCCBK3+Ddo757s6L8g=" crossorigin="anonymous" />
</head>

<body>
  <nav class="navbar navbar-expand-lg bg-dark navbar-dark">
    <div class="container"> <button class="navbar-toggler navbar-toggler-right border-0 p-0" type="button" data-toggle="collapse" data-target="#navbar14">
        <p class="navbar-brand mb-0 text-white">
          <i class="fa d-inline fa-lg fa-stop-circle"></i> BRAND </p>
      </button>
      <div class="collapse navbar-collapse" id="navbar14">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item"> <a class="nav-link" href="/">问答系统</a> </li>
          <li class="nav-item"> <a class="nav-link" href="/Code">代码检测</a> </li>
        </ul>
        <p class="d-none d-md-block lead mb-0  text-white"> <i class="fa d-inline fa-lg fa-stop-circle"></i> <b>C语言程序设计诊断专家系统</b> </p>
        <ul class="navbar-nav ml-auto">
          <li class="nav-item mx-1"> <a class="nav-link" href="#">
            </a> </li>
          <li class="nav-item mx-1"> <a class="nav-link" href="#">
            </a> </li>
          <li class="nav-item mx-1"> <a class="nav-link" href="#">
              <i class="fa fa-github fa-fw fa-lg"></i>
            </a> </li>
        </ul>
      </div>
    </div>
  </nav>
  <div class="bg-dark text-white py-1">
    <div class="container">
      <textarea class="w-100" rows="30" id="code"></textarea>
      <div class="row">
        <div class="col-md-12"><a class="btn btn-primary btn-block my-1" href="javascript:CheckCode()">提交检测</a></div>
      </div>
    </div>
  </div>
  <div class="py-3 bg-dark text-light" >
    <div class="container">
      <div class="row">
        <div class="col-md-12 text-center"> <i class="d-block fa fa-stop-circle mb-3 text-muted fa-3x"></i>
          <p> <a href="https://goo.gl/maps/AUq7b9W7yYJ2" target="_blank"> C语言程序设计诊断专家系统 <br>人工智能课程设计</a> </p>
          <p> <a href="tel:+246 - 542 550 5462">162班 1600802046 李怡龙</a> </p>
          <p class="mb-0"> <a href="mailto:leeli@live.cn">leeli@live.cn</a> </p>
        </div>
      </div>
      <div class="row">
        <div class="col-md-12 d-flex align-items-center justify-content-center my-3"> <a href="https://www.cnblogs.com/lee-li/">
            <i class="d-block fa fa-bold text-muted fa-lg mr-2"></i>
          </a> <a href="https://github.com/leeli73/">
            <i class="d-block fa fa-github text-muted fa-lg mx-2"></i>
          </a> 
         </div>
      </div>
      <div class="row">
        <div class="col-md-12 text-center">
          <p class="mb-0">计算机技术与应用系</p>
        </div>
      </div>
    </div>
  </div>

  <div class="modal fade" id="myModal">
      <div class="modal-dialog modal-lg">
        <div class="modal-content">
     
          <!-- 模态框头部 -->
          <div class="modal-header">
            <h4 class="modal-title">代码检测结果</h4>
            <button type="button" class="close" data-dismiss="modal">&times;</button>
          </div>
     
          <!-- 模态框主体 -->
          <div class="modal-body">
              <table class="table table-bordered">
                  <thead>
                    <tr>
                      <th>错误类型</th>
                      <th>行数</th>
                      <th>错误描述</th>
                      <th>解决建议</th>
                    </tr>
                  </thead>
                  <tbody id="show">
                    <tr>
                      <td>NULL</td>
                      <td>NULL</td>
                      <td>NULL</td>
                      <td>NULL</td>
                    </tr>
                  </tbody>
              </table>
          </div>
     
          <!-- 模态框底部 -->
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="ReloadCodeWithErr()">将错误置入代码</button>
          </div>
     
        </div>
      </div>
    </div>

    
  <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.0/codemirror.js" integrity="sha256-CIOyFApzNth/IeMGNYIKfxeAX0NXWrYcbopFpQ32ArU=" crossorigin="anonymous"></script>
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.0/addon/hint/show-hint.min.js" integrity="sha256-P946oK/OkcGC8rs/phAXZRvTADKK0V+x23Jbl0DilgQ=" crossorigin="anonymous"></script>  
</body>
<script>
  var editor = CodeMirror.fromTextArea(code, {
    lineNumbers: true,
    mode: "text/cpp"
  });
  editor.on("change", function () {
     editor.showHint();
  });
  editor.setSize('auto','600px');
  var OldCode =new Array()
  function CheckCode()
  {
    var code = btoa(encodeURIComponent(editor.getValue()))
    OldCode = editor.getValue().split("\n")
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        //alert(xmlhttp.responseText);
        if(xmlhttp.responseText == "not Find")
        {
          alert("未找到问题!")
          returns
        }
        var temp1 = xmlhttp.responseText.split("\n")
        var table_code = ""
        for(var i=0;i<temp1.length;i++)
        {
          if(temp1[i]!="")
          {
            var temp2 = temp1[i].split(" ")
            table_code = table_code + "<tr><td>"+temp2[1]+"</td><td>"+temp2[0]+"</td><td>"+temp2[2]+"</td><td>"+temp2[3]+"</td></tr>"
            OldCode[parseInt(temp2[0])-1] = OldCode[parseInt(temp2[0])-1] + "  //代码检查信息:" + temp2[1]+","+temp2[2]+","+temp2[3]
          }
        }
        document.getElementById("show").innerHTML = table_code
        $('#myModal').modal();

      }
    }
    var data = "code=" + code;
    xmlhttp.open("POST", "/CheckCPP", true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.send(data);
  }
  function ReloadCodeWithErr()
  {
    var code = ""
    for(var i=0;i<OldCode.length;i++)
    {
      code = code + OldCode[i] + "\n"
    }
    editor.setValue(code)
  }
</script>
</html>